package com.dudu.common.util

import android.view.View
import android.view.Window
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat

/**
 * <pre>
 *     author : dzc
 *     time   : 2025/02/10
 *     desc   : 系统导航栏
 *              https://developer.android.google.cn/develop/ui/views/layout/insets?hl=zh-cn
 * </pre>
 */
object NavigationBarUtil {

    /**
     * 隐藏导航栏
     * 上滑显示，自动隐藏
     */
    fun hideNavigationBar(window: Window){
        // 隐藏导航栏
        var systemUiVisibility = window.decorView.systemUiVisibility
        systemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        window.decorView.systemUiVisibility = systemUiVisibility

        // 上滑后显示导航栏，然后自动隐藏自动隐藏
        // 不添加，上滑后显示导航栏不会自动隐藏
        val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
        // Configure the behavior of the hidden system bars.
        windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    }

}